package com.foreknow.demo02;

import java.util.Scanner;

/**
 * 登录注册功能的实现
 */
public class Test02 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String answer = "y";
        String information1 = "";
        String password1 = "";
        boolean zhuce = true;

        do {
            System.out.println("*******************************************");
            System.out.println("1.注册");
            System.out.println("2.登录");
            System.out.println("3.抽奖");
            System.out.println("*******************************************");
            System.out.println("请输入菜单：");
            int choice = input.nextInt();
            switch(choice){
                case 1:
                    int s = (int)(Math.random()*(9999-1000+1))+1000;//产生1000-9999的随机数
                    System.out.println("注册");
                    System.out.println("请填写个人信息：");
                    System.out.println("用户：");
                    information1 = input.next();
                    System.out.println("请输入密码：");
                    password1 = input.next();
                    System.out.println("注册成功，请记好您 的会员号");
                    System.out.println("用户名    密码      会员号");
                    System.out.println(information1 + "   " + "   " + password1 + "" + s);
                    zhuce = true;
                    break;
                case 2:
                    if (zhuce){
                        for (int i=0;i<3;i++){
                            System.out.println("登录");
                            System.out.println("用户名：");
                            String information = input.next();
                            System.out.println("密码：");
                            String password = input.next();
                            //判断登录的信息与注册时候的信息相同，字符串之间的比较一定要使用equals
                            if (information.equals(information1)&&password.equals(password1)){
                                System.out.println("欢迎您" + information1);
                                zhuce = true;
                                break;
                            }else if (i<3){
                                System.out.println("输入错误,还有" + (2-i) + "次机会");
                            }else{
                                System.out.println("3次错误的用户信息");
                            }
                        }
                    }else{
                        System.out.println("请先注册，然后才能进行登录");
                    }



                    break;
                case 3:
                    System.out.println("抽奖");
                    break;
            }
            System.out.println("是否继续(y/n):");
            answer = input.next();
        }while(answer.equals("y"));
            if (answer.equals("n")){
                System.out.println("退出程序，谢谢使用！！！");
            }
    }
}